//
//  DSSHphotoArry.m
//  DSSH
//
//  Created by Fuhao on 16/4/13.
//  Copyright © 2016年 lcy. All rights reserved.
//

#import "DSSHphotoArry.h"

@interface DSSHphotoArry ()<UIScrollViewDelegate>
{
    UIScrollView * _blackGs;
}

@end

@implementation DSSHphotoArry

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    _dataarray = @[@"tupian",@"tupian",@"tupian",@"tupian"];
    
    //创建背景的srcollview
    _blackGs = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, ZYAppWidth, ZYAppHeight)];
    _blackGs.contentSize = CGSizeMake(_dataarray.count * ZYAppWidth, 0);
    _blackGs.pagingEnabled = YES;
    _blackGs.delegate = self;
    [self.view addSubview:_blackGs];
    //根据数据源创建相应的imageview
    for (int i =0 ; i < _dataarray.count;  i ++) {
        UIImageView *imagev = [[UIImageView alloc] init];
        
        [_blackGs addSubview:imagev];
        [imagev mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_blackGs.mas_top).with.offset(0);
            make.left.equalTo(_blackGs.mas_left).with.offset(i*ZYAppWidth);
            make.height.mas_equalTo(ZYAppHeight);
            make.width.mas_equalTo(ZYAppWidth);
        }];
        [imagev setImage:[UIImage imageNamed:_dataarray[i]]];
    }
    
    //设置顶部索引的初始值
    self.navigationItem.title = [NSString stringWithFormat:@"1/%ld",_dataarray.count];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    //根据滚动的距离改变上部索引
    NSString * titlestr = self.navigationItem.title;
    NSInteger index = _blackGs.contentOffset.x/ZYAppWidth +1;
    self.navigationItem.title =  [titlestr stringByReplacingCharactersInRange:NSMakeRange(0, 1) withString:[NSString stringWithFormat:@"%ld",(long)index]];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
